﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataSource;
using BLL;
using System.Text;
using TradeWorkstation.Models;
namespace TradeWorkstation.Controllers
{
    public class SellController : Controller
    {
        // GET: Sell
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Handler()
        {

            /*if (!ModelState.IsValid || file == null) 
            {
                Response.StatusCode = 400;
                return new EmptyResult();
            }
            else
            {*/
            // user u = new user();//从session处获得
            Item item = new Item();
            item.IID = Guid.NewGuid();
            item.Title = "First Product"; //sf.title;
            item.CID = 2;// sf.cid;
            item.UID = Guid.NewGuid();//new user().uID;//此处通过session获取，赋值给user，再获取
            item.Type = 1;
            item.Price = 58;// sf.price;
            item.Detail = "快来买快来买";// sf.detail;
            item.Bargain = 1;// sf.bargain;
            item.Priority = 1;
            item.Tel = "1232323";// sf.tel;
            item.QQ = "332323";// sf.qq;
            item.Way = "在线支付";// sf.way; 
            // string url = GetPath(u.uName,sf.type);
            Pic pic = new Pic();
            //pic.PID = Guid.NewGuid();
            pic.Url = "ddd";//url;
            pic.IID = item.IID;
            pic.Order = 1;
            // pic.Status = 1;
            if (SellService.InsertSellForm(item))
            {
                //if (PicService.InsertPic(file,url,pic))
                //{
                return Content("<script type='text/javascript'>alert('您已经上传成功！');</script>");
                //}
                //else
                //{
                //  return Content("<script type='text/javascript'>alert('保存图片信息失败！');</script>");
                //}
            }
            else
            {
                return Content("<script type='text/javascript'>alert('上传失败，请刷新页面，填写必要的信息！');</script>");
            }


        }
        /*  public ActionResult Search(int order,int cid,int page)
         {
             var vm = SellService.GetBuyList(order,cid,page);
             ViewData.Model = vm;
             return View();
         }
        private string GetPath(string uname, int type)
         {
             StringBuilder sb = new StringBuilder();
             sb.Append(Server.MapPath("/UpLoadFiles/"));
             sb.Append(uname);
             sb.Append(@"/");
             sb.Append(type);
             sb.Append(@"/");
             sb.Append(DateTime.Now.Ticks+".jpeg");
             return sb.ToString();
         }*/
    }
}
